﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Media;
using SensorDrone.Net;

namespace SensorDroneStudio.Services
{
    internal class MockSensorDrone : ISensorDrone
    {
        private readonly string _name;

        public MockSensorDrone(string name)
        {
            _name = name;
        }

        public event Action<string, bool> Status = (s, b) => { };

        public event Action<Reading> Reading = r => { };

        public event Action<string> Error = s => { };

        public string Version
        {
            get { return Guid.NewGuid().ToString(); }
        }

        public string Address
        {
            get { return Guid.NewGuid().ToString(); }
        }

        public string Name
        {
            get { return _name; }
        }

        public bool Connected
        {
            get { return true; }
        }

        public async Task<bool> ConnectAsync()
        {
            return await Task.FromResult(true);
        }

        public IEnumerable<ISensor> Sensors
        {
            get { return new[] {new BaseSensor {Name = "Ambient",}, new BaseSensor {Name = "Pressure",}}; }
        }

        public Task<Reading> SampleAsync(string sensor)
        {
            return Task.Run(() => new Reading(sensor, "units", "100"));
        }

        public bool Cancelled
        {
            get { return false; }
        }

        public event PropertyChangedEventHandler PropertyChanged = (o, p) => { };

        public void Dispose()
        {
        }

        public void Register(ISensor sensor)
        {
        }


        public Task<IEnumerable<string>> EnableAllAsync()
        {
            return Task.Run(() => new[] {"", ""}.AsEnumerable());
        }


        bool ISensorDrone.Enable(string senor)
        {
            return true;
        }

        public Task<bool> EnableAsync(string sensor)
        {
            return Task.Run(() => true);
        }

        bool ISensorDrone.Disable(string sensor)
        {
            return true;
        }

        public Reading Sample(string sensor)
        {
            return new Reading();
        }

        public Task Leds(Color color)
        {
            return Task.FromResult(false);
        }

        public Task<IEnumerable<Reading>> SampleAsync(IEnumerable<string> sensors)
        {
            return Task.Run(() => sensors.Select(sensor => new Reading(sensor, "units", "100")));
        }


        public void Close()
        {
        }
    }
}